<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0;"/>
<title id="title">登录页面</title>
<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="../showstatic/js/layer-v3.0.3/layer/mobile/need/layer.css" rel="stylesheet" type="text/css" />
<link href="../showstatic/css/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../showstatic/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../showstatic/js/phone.js" ></script>
<script type="text/javascript" src="../showstatic/js/layer-v3.0.3/layer/mobile/layer.js"></script>
</head>

<body>
	<header class="header">
        <a href="javascript:history.back(-1)" class="fa fa-angle-left"></a>
        <span class="names" id="aa">登录</span>
    </header>
    <div class="login_contnet">
    	<div class="commons user">
        	<i class="fa fa-user"></i>
            <input type="number"   name="tel" class="tel" id="account" placeholder="请输入您的账号（手机号）" />
        </div>
        <div class="commons pasd">
        	<i class="fa fa-unlock-alt"></i>
            <input type="password"  value="" name="pasd" id="pas" class="pasd" placeholder="请输入6~16位密码" />
        </div>
        <div class="commons user">
            <input type="text"     placeholder="请输入验证码" id="code"/>
            <a href="javascript:void(0)" onclick="getcode()" id="chang_href" class="common_use change" style="color: chocolate ;font-size: 30px">获取手机验证码</a>
        </div>
        <div class="login">登录</div>
        <a href="/movieshow/regist.html" class="common_use register" style="color: chocolate">还没有账号,请注册!</a>
        <a href="javascript:void(0)" class="common_use change" onclick="change_pas()" id="changetext" style="color: chocolate">忘记密码?</a>
    </div>
    
<script type="text/javascript">
    var param1 = false;
    var param2 = false;
    var param3 = false;

    function mesLay(content){
        layer.open({
            content: content
            ,skin: 'msg'
            ,time: 3
        });
    }


    function getcode(){
       // alert('1111')
        var flag1 = true;
        var flag2 = true;
        if(param1 == true){
            if(flag1 == true){
               // alert('22222')
                $.ajax({
                    url:'/login/getCode',
                    data:{'account':$("#account").val()},
                })

                $("#chang_href").removeAttr("onclick");
            }
            if(flag2 == true){
                var setTime;
                var time=60;
                setTime=setInterval(function(){
                    if(time<=0){
                        $("#chang_href").text("重新获取手机验证码");
                        clearInterval(setTime);
                        $("#chang_href").attr('onclick','getcode()')
                        return;
                    }
                    time--;
                    $("#chang_href").text(time+"秒后重新获取验证码")
                },1000);
            }
        }else{
            var reg = /^1[34578]\d{9}$/;
            var phoneVal = $('.tel').val();
            if(reg.test(phoneVal)){
                param1 = true;
            }else{
                mesLay('手机号码有误！')
            }
        }
    }

$(function(){




	function phone(){
		var reg = /^1[34578]\d{9}$/;
		var phoneVal = $('.tel').val();
		if(reg.test(phoneVal)){
            //$("#chang_href").prop('href','/getCode?account='+$("#chang_href").val());
            param1 = true;
		}else{
			mesLay('手机号码有误！')
			//return false;
		}
	}
	
	function pasd(){
		var psdVal = $('#pas').val();

		if(psdVal.length < 6){
			mesLay('您的密码少于6位数！');
			//return false;
		}else{
			param2 = true;
		}
	}

    function code(){
        var code = $('#code').val();
        if(code=='' | code == null){
            mesLay('请输入验证码');
            //return false;
        }else{
            param3 = true;
        }
    }

    $('#code').blur(function () {
        code();
    })

	$('.tel').blur(function(){
		phone();
	});
	
	$('.pasd').blur(function(){
		pasd();
	});



	/*function getcode(){
        var flag1 = true;
        var flag2 = true;
        if(param1 == true){
            if(flag1 == true){
                $.ajax({
                    url:'/getCode',
                    data:{'account':$("#account").val()},
                })
                //flag1 = false;
                $("#chang_href").removeAttr("onclick");
            }
            //$("#chang_href").text("");
            if(flag2 == true){
                //flag2 = false;
                var setTime;
                var time=60;
                setTime=setInterval(function(){
                    if(time<=0){
                        $("#chang_href").text("重新获取手机验证码");
                        clearInterval(setTime);
                        $("#chang_href").attr('onclick','getcode()')
                        //flag1 = true;
                        //flag2 = true;
                        return;
                    }
                    time--;
                    $("#chang_href").text(time+"秒后重新获取验证码")
                },1000);
            }
        }else{
            phone();
        }
    }*/


	$('.login').on('click',function(){

	    if(param2& param1 & param3){
            var url1 = '/login/login';
	        if(type =='change'){
                url1 ='/login/changePas';
            }
	        $.ajax({
                url:url1,
                data:{'account':$("#account").val(),'password':$("#pas").val(),'verificationCode':$("#code").val(),},
                success:function (data) {
                    mesLay(data);
                    //alert(data)
                    if(data == '登录成功'){
                        location.href="/movieshow/index.html";
                    }
                    if(data == '修改成功'){
                        location.href="/movieshow/index.html";
                    }
                }
            })
        }else{
	        phone();
	        pasd();
	        code();
        }
	});
})


var type = 'login';
function change_pas() {
    $("#title").text("修改密码");
    $("#aa").text("修改密码并登陆");
    $("#pas").attr('placeholder','输入新的密码');
    $("#changetext").text('');
    type = 'change';
}
</script>
    
</body>
</html>
